package io.codegeneratetool.web.service;

import javax.sql.DataSource;

import io.codegeneratetool.web.entity.DBConnection;

import org.springframework.jdbc.core.JdbcTemplate;

public class JDBCTemplateFactory {

	static JdbcTemplate jdbcTemplate = new JdbcTemplate();
	public static String currentDB ;
	public static JdbcTemplate createJdbcTemplate(DBConnection connection){
		if(currentDB!=null && currentDB.equals(connection.getDbid())){
			return jdbcTemplate;
		}
		 
		DataSource createDataSource = DataSourceFactory.createDataSource(connection);
		jdbcTemplate.setDataSource(createDataSource); 
		currentDB = connection.getDbid();
		return jdbcTemplate;
	}
	
	
	
}
